package main

func addToArrayForm(num []int, k int) []int {
	var (
		ans    []int
		i      int = len(num) - 1
		first  int
		second int
		carry  int = 0
		sum    int
	)

	for i >= 0 || k > 0 {
		if i >= 0 {
			first = num[i]
		} else {
			first = 0
		}

		if k > 0 {
			second = k % 10

		} else {
			second = 0
		}

		sum = carry + first + second
		carry = sum / 10
		sum %= 10

		ans = append(ans, sum)

		i--
		k /= 10
	}
	if carry != 0 {
		ans = append(ans, carry)
	}

	left, right := 0, len(ans)-1

	for left < right {
		ans[left], ans[right] = ans[right], ans[left]
		left++
		right--
	}

	return ans
}

func main() {
	test := []int{1, 2, 0, 0}
	addToArrayForm(test, 34)
}
